<?php
/**
 * Created by JetBrains PhpStorm.
 * User: dodasso
 * Date: 7/14/13
 * Time: 8:10 PM
 * To change this template use File | Settings | File Templates.
 */

define('APP_ROOT', realpath(__DIR__ . '/../..'));

require_once(APP_ROOT . '/modules/persistance/DBConnector.php');
require_once(APP_ROOT . '/modules/persistance/ModulePersistance.php');
require_once(APP_ROOT . '/modules/common/Errors.php');
require_once(APP_ROOT . '/modules/common/CommonModule.php');

use persistance\DBConnector;
use common\Errors;
use common\CommonModule;

function testListLineOfbussiness() {
    $dbconn = new DBConnector();
    $dbconn->connect();
    $cmod = new CommonModule();
    if(!$cmod->init($dbconn)) {
        print('testListLineOfbussiness(): FAIL' . PHP_EOL);
        return;
    };
    $rs = $cmod->listLineOfBussiness();
    $json = json_decode($rs, true);
    if((is_null($json)) ||
        ($json['errorCode'] != Errors::INTEGRAL_ERR_NONE)) {
        print('testListLineOfbussiness(): FAIL' . PHP_EOL);
        return;
    }

    print('testListLineOfbussiness(): OK' . PHP_EOL);
}

function testListMeasuringUnits() {
    $dbconn = new DBConnector();
    $dbconn->connect();
    $cmod = new CommonModule();
    if(!$cmod->init($dbconn)) {
        print('testListLineOfbussiness(): FAIL' . PHP_EOL);
        return;
    };
    $rs = $cmod->listMeasuringUnits();
    $json = json_decode($rs, true);
    if((is_null($json)) ||
        ($json['errorCode'] != Errors::INTEGRAL_ERR_NONE)) {
        print('testListMeasuringUnits(): FAIL' . PHP_EOL);
        return;
    }

    print('testListMeasuringUnits(): OK' . PHP_EOL);
}

testListLineOfbussiness();
testListMeasuringUnits();
